# coding = utf-8
import numpy as np
import cv2 as cv

import matplotlib.pyplot as plt

# 导入资源
image = cv.imread('D:\\data\\real-test\\IMG_5470.JPG')
image_copy = np.copy(image)
image_copy = cv.cvtColor(image_copy, cv.COLOR_BGR2RGB)
gray = cv.cvtColor(image_copy, cv.COLOR_RGB2GRAY)
gray = np.float32(gray)

# 参数为hessian矩阵的阈值
surf = cv.xfeatures2d.SURF_create(400)
# 设置是否要检测方向
surf.setUpright(True)
# 找到关键点和描述符
keypoints, des = surf.detectAndCompute(gray, None)

# 把特征点标记到图片上
corner_image = np.copy(image_copy)
for point in keypoints:
    cv.circle(corner_image, (int(point.pt[0]), int(point.pt[1])), 1, (0,255,0), 1)
cv.imwrite('SURF.png', corner_image)
plt.imshow(corner_image)
plt.show()